package cn.edu.nju.software.model.user;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.nju.software.model.DatabaseHelper;

public class UserLoginVerifier {

	private static DatabaseHelper dbHelper;
	
	public UserLoginVerifier() {
		if (dbHelper == null) {
			dbHelper = new DatabaseHelper();
		}
	}
	
	public boolean verify(String username, String password) {
		boolean result = false;
		
		ResultSet rs = dbHelper.fetchAllRecord(DatabaseHelper.TID_MEMBER);
		if (rs != null) {
			try {
				rs.beforeFirst();
				while (rs.next()) {
					String u = rs.getString(2);
					String p = rs.getString(3);
					if (username.equals(u) && password.equals(p)) {
						result = true;
						break;
					}
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return result;
	}
}
